package com.gaoshi.chapter4;

import java.time.DayOfWeek;
import java.time.LocalDate;

/**
 * 打印当前月的日历
 */
public class CalendarTest {
    public static void main(String[] args) {
        LocalDate date = LocalDate.now();
        int today = date.getDayOfMonth();
        int month = date.getMonthValue();

        date = date.minusDays(today - 1);
        DayOfWeek dayOfWeek = date.getDayOfWeek();
        int start = dayOfWeek.getValue();

        System.out.println("Mon Tue Wed Thu Fri Sat Sun");
        for (int i = 1; i < start; i++) {
            System.out.print("    ");
        }

        while (month == date.getMonthValue()) {
            System.out.printf("%3d", date.getDayOfMonth());
            if (today == date.getDayOfMonth()) {
                System.out.print("*");
            } else {
                System.out.print(" ");
            }
            date = date.plusDays(1);
            if (date.getDayOfWeek().getValue() == 1) {
                System.out.println();
            }
        }
        if (date.getDayOfWeek().getValue() != 1) {
            System.out.println();
        }
    }
}
